﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace IntillisenseLib
{
    public class ObjectRoot:ObjectTemplete
    {
        private List<ObjectTemplete> objList;

        public List<ObjectTemplete> ObjList
        {
            get { return objList; }            
        }

        public ObjectRoot()
        {
            objList = new List<ObjectTemplete>();
        }

        public void AddObj(ObjectTemplete obj)
        {
            if (objList == null)
            {
                objList = new List<ObjectTemplete>();
            }
            if (objList.Where(o => o.ObjType == obj.ObjType && o.GetParameterDisplayName() == obj.GetParameterDisplayName()).Count() > 0)
            {
                throw new Exception("Object is already existed");
            }            
            objList.Add(obj);
        }
        public void DeleteObj(ObjectTemplete obj)
        {
            if (objList != null)
            {
                objList.Remove(obj);
            }
        }
        public ObjectTemplete FindObject(String objectName, eObjectType type)
        {
            return objList.Where(o => o.ObjType == type && o.GetParameterDisplayName() == objectName).FirstOrDefault();
        }
        public void DeleteAllObject(eObjectType type)
        {
            objList.RemoveAll(o => o.ObjType == type);
        }

        public override string GetParameterDisplayName()
        {
            return "";
        }

        public override string GetParameterValue()
        {
            return "";
        }

        public override string GetFullPath()
        {
            return "";
        }

        public override List<ObjectTemplete> GetAllChilds()
        {
            return objList;
        }
    }
}
